import time

from selenium.webdriver.common.by import By

from common.base import Base


class OrderGeneratedPage(Base):
    url = 'http://139.129.26.163/flow.php?step=consignee'

    # 申通快递
    def select_address(self):
        time.sleep(3)
        self.click((By.XPATH, '/html/body/div[6]/form[1]/div/table/tbody/tr[5]/td/input[1]'))
        time.sleep(3)

    def distribution_mode1(self):
        self.click((By.XPATH, '//input[@value="5"]'))

    # 邮局平邮
    def distribution_mode2(self):
        self.click((By.XPATH, '//input[@value="6"]'))

    # 是否保价
    def is_parcel_insurance(self):
        self.click((By.ID, 'ECS_NEEDINSURE'))

    # 支付方式
    def payment1(self):
        self.click((By.XPATH, '//input[@name="payment" and @value="1"]'))

    def payment2(self):
        self.click((By.XPATH, '//input[@name="payment" and @value="2"]'))

    def payment3(self):
        self.click((By.XPATH, '//input[@name="payment" and @value="3"]'))

    # 商品列表修改
    def goods_change(self):
        self.click((By.XPATH, '//form[@id="theForm"]/div[1]/h6/a'))

    # 用户信息修改
    def user_info_change(self):
        self.click((By.XPATH, '//form[@id="theForm"]/div[3]/h6/a'))

    # 包装
    def is_packaging1(self, ):
        self.click((By.XPATH, '//input[@name="pack" and @value="0"]'))

    def is_packaging2(self):
        self.click((By.XPATH, '//input[@name="pack" and @value="1"]'))

    # 查看包装图片
    def check_packaging(self):
        self.click((By.XPATH, '//table[@id="packTable"]/tbody/tr[3]/td[5]/a'))

    # 祝福贺卡
    def greeting_card1(self):
        self.click((By.XPATH, '//input[@name="card" and @value="0"]'))

    def greeting_card2(self):
        self.click((By.XPATH, '//input[@name="card" and @value="1"]'))

    # 祝福语
    def greetings(self, content):
        self.send_keys((By.NAME, 'card_message'), content)

    # 查看贺卡
    def check_greeting_card(self):
        self.click((By.XPATH, '//table[@id="cardTable"]/tbody/tr[3]/td[5]/a'))

    # 选择红包下拉框
    def select_red_packet(self, index):
        self.select_by_index((By.ID, 'ECS_BONUS'), index)

    # 红包序列号
    def serial_number(self, serial_number):
        self.send_keys((By.NAME, 'bonus_sn'), serial_number)

    # 验证红包
    def verification(self):
        self.click((By.NAME, 'validate_bonus'))

    # 开发票
    def is_invoice(self):
        self.click((By.ID, 'ECS_NEEDINV'))

    # 发票类型
    def select_invoice_type(self, index):
        self.select_by_index((By.ID, 'ECS_INVTYPE'), index)

    # 发票抬头
    def invoice_title(self, title):
        self.send_keys((By.ID, 'ECS_INVPAYEE'), title)

    # 发票内容
    def invoice_content(self, index):
        self.select_by_index((By.ID, 'ECS_INVCONTENT'), index)

    # 订单附言
    def order_postscript(self, content):
        self.send_keys((By.ID, 'postscript'), content)

    # 缺货处理
    def shortage_of_processing1(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="0"]'))

    def shortage_of_processing2(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="1"]'))

    def shortage_of_processing3(self):
        self.click((By.XPATH, '//input[@name="how_oos" and @value="2"]'))

    # 提交
    def submit(self):
        self.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))
